<template>
    <XPTable :search='false' ref='tableRef' :api='pageApi' :columns='columns'>
        <template #name='{record}'>
            <router-link :to='"/strategy/follow/" + record.id'>{{record.name}}</router-link>
        </template>
        <template #status='{record}'>
            <a-tag>{{record.status_text}}</a-tag>
            <!-- <XBackTestStatus :status='record.status' /> -->
        </template>
        <template #action='{record}'>
            <XRequestButton v-if='record.status != 2' isConfirm confirmText='确定结束吗' :click='() => endFollow(record)'>
                <a-button size='small' danger ghost>结束</a-button>
            </XRequestButton>
        </template>
    </XPTable>
</template>

<script lang='ts' setup>
    import { reactive, ref } from 'vue'
    import { strategyFollowPageApi, endFollowApi } from '@/api/strategyFollow'
    import { Column } from '../../../types'
import { message } from 'ant-design-vue'
    async function pageApi(params:any) {
        return strategyFollowPageApi(params)
    }

    const tableRef = ref()

    const columns = reactive<Column[]>([
        {title : '名称', dataIndex : 'name', align : 'center', inFilter : true, filter : {name : 'keyword'}},
        {title : '创建时间', dataIndex : 'create_at', align : 'center'},
        {title : '状态', dataIndex : 'status', align : 'center'},
        {title : '操作', dataIndex : 'action', align : 'center'},
    ])


    async function endFollow(record:any) {
        const rs = await endFollowApi(record.id)
        if(rs.success) {
            tableRef.value.load()
            message.success('结束成功')
        }else {
            message.error(rs.msg)
        }
    }

</script>
